<?php
  require_once('../db.php');

  if(isset($_GET['mode']) &&
  $_GET['mode'] == 'del' ) {
    $id = $_GET['id'];
    $delQuery = "DELETE FROM `users`
    WHERE `id`='$id'";
    print_q($delQuery);
    mysql_query($delQuery) or die(mysql_error());
    if(mysql_affected_rows() == 1){
      echo "<h4>Record Deleted successfully.</h4>";
    }
  }


  $query = "SELECT * FROM `users`";
  print_q($query);

  $result = mysql_query($query) or die(mysql_error());
  $totalUser = mysql_num_rows($result);
?>
<p>
  <em>Total Records </em>:<strong><?=$totalUser?></strong>
</p>

<table  border="1" cellpadding="0" cellspacing="0" width="80%" align="center">
  <thead>
    <tr>
      <th colspan="6">:: ALL USERS ::</th>
    </tr>
    <tr>
      <th align="left">#</th>
      <th align="left">User Name</th>
      <th align="left">Email</th>
      <th align="left">Added date</th>
      <th align="left">Status</th>
      <th align="left">Action</th>
    </tr>
  </thead>
  <tbody>
<?php
  while($ans = mysql_fetch_assoc($result))
  {
    $id = $ans['id'];
?>
    <tr>
      <td ><?=$id?></td>
      <td ><?=$ans['uname']?></td>
      <td >

<a href="mailto:<?=$ans['email']?>"><?=$ans['email']?></a>

      </td>
      <td ><?=date('d-M-Y',strtotime($ans['added_date']))?></td>
      <td ><?=getStatus($ans['status'])?></td>
      <td align="right">Edit / <a href="users.php?mode=del&id=<?=$id?>" onClick="return confirm('Are you sure ?')">Delete</a></td>
    </tr>
<?php
  }
?>
  </tbody>
</table>
